package com.ifinc.common.protocol.i8583;


import com.ifinc.common.protocol.i8583.field.Field;
import com.ifinc.common.utils.Log;
import com.ifinc.common.utils.encode.ByteUtil;
import org.slf4j.Logger;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * User: luotao
 * Date: 13-11-15
 * Time: 13:42
 */
public abstract class I8583Response {

    private static Logger logger = Log.makeLogger(I8583Response.class);

    protected Map<Integer, Field> data = new LinkedHashMap<Integer, Field>();

    LinkedHashMap<Integer, Field> fieldInfo = new LinkedHashMap<Integer, Field>();

    LinkedHashMap<Integer, Field> macInfo = new LinkedHashMap<Integer, Field>();

    protected List<Byte> dataByte = new LinkedList<Byte>();

    public static final int FIELD_LEN = 64;

    protected String zmk;

    protected String zak;

    protected boolean needMac = true;

    public boolean isNeedMac() {
        return needMac;
    }

    public void setNeedMac(boolean needMac) {
        this.needMac = needMac;
    }



    public void addFiled(Integer index, String str) {
        Field field = fieldInfo.get(index);
        field.setSrcValue(str);
        field.setFieldId(index);
        data.put(index, field);
    }

    public byte[] encode() {

        return ByteUtil.list2ByteArray(dataByte);

    }



    public Map<Integer, Field> getData() {
        return data;
    }

    public String getZmk() {
        return zmk;
    }

    public void setZmk(String zmk) {
        this.zmk = zmk;
    }

    public String getZak() {
        return zak;
    }

    public void setZak(String zak) {
        this.zak = zak;
    }

    public LinkedHashMap<Integer, Field> getMacInfo() {
        return macInfo;
    }

    public abstract void makeFieldInfo(LinkedHashMap<Integer, Field> fieldMap);

    public abstract void makeMacInfo(LinkedHashMap<Integer, Field> fieldMap);
}
